package com.youyun56.gps.android.common;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.util.Log;

public class ApplicationUtils {
    private final static String tag = ApplicationUtils.class.getName();

    public static String getVersion(Context context) {
        String versionName = "";

        try {

            // ---get the package info---

            PackageManager pm = context.getPackageManager();

            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);

            versionName = pi.versionName;

            if (versionName == null || versionName.length() <= 0) {

                return "";

            }

        }
        catch (Exception e) {

            Log.e(tag, "Exception", e);

        }

        return versionName;
    }

    public static String getMobile(Activity activity) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getLine1Number();
    }

    public static String getIMSI(Context activity) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        // String deviceid = tm.getDeviceId();
        // String tel = tm.getLine1Number();
        // String imei = tm.getSimSerialNumber();
        // String imsi = tm.getSubscriberId();
        return tm.getDeviceId();
    }

}
